Skip to content

[client] Make conntrack cap and UDP cleanup tests deterministic - #8625

Merged
mlsmaycon merged 1 commit into
mainfrom
work/adoring-newton-yrav86
Nov 14, 2026
Merged

mlsmaycon merged 1 commit into
mainfrom
work/adoring-newton-yrav86

Conversation

@mlsmaycon

@mlsmaycon mlsmaycon commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes

Two conntrack tests flake in CI on PRs that don't touch the client (seen on #8619 and #8620).

TestUDPCapEvicts (Windows): eviction takes the entry with the smallest lastSeen and breaks ties by map iteration order. On Windows' coarse clock, flows admitted back to back can share a timestamp, so the flow the test calls "oldest" can survive. I reproduced this on Linux by giving every flow the same lastSeen, and the same flow (SrcPort 0x7530) survived. The cap tests now set each flow's lastSeen to a distinct, increasing value after it's admitted, so "oldest" is always well defined. The TCP and ICMP cap tests had the same weakness and get the same fix. I left production eviction alone: tied entries are equally old as far as the tracker can tell, and the scan is already a sampled approximation of LRU.

TestUDPTracker_Cleanup (macOS): it slept 100ms and hoped the 25ms ticker had fired. Under CPU load it failed 1 run in 200 locally. It now sends the cleanup routine a tick over a channel the test owns, expires flows by setting lastSeen directly, and waits for the routine to exit. It also adds a fresh flow that has to survive cleanup.

Verified with go test -race -count=200 (and -count=1000), with GOMAXPROCS=1 and with 16 busy loops on 4 cores: no failures. Both tests still fail when eviction is changed to pick the newest flow, or cleanup is changed to remove everything.

Issue ticket number and link

No issue: this changes tests only.

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • I ran and tested this change locally — I did not rely on CI to find out whether it works
  • This PR has a single purpose (not a fix + refactor + feature in one)
  • This change is a trivial fix, OR it links an issue the NetBird team agreed on beforehand. Changes to the public API, gRPC protocols, functionality behavior, CLI / service flags, or new features always need that agreement first. See CONTRIBUTING.md.

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Only test code changes; nothing user-facing.

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__


Generated by Claude Code

View guided diff Turn on auto-fix

Summary by CodeRabbit

  • Tests
    • Improved coverage for connection limits across TCP, UDP, and ICMP flows.
    • Made UDP cleanup tests more predictable by checking that expired connections are removed while fresh connections remain.

The cap tests assert that the oldest flow is evicted, but eviction picks
the smallest lastSeen and breaks ties by map iteration order. On a coarse
clock (Windows) flows admitted back to back share a timestamp, so the
"oldest" flow could survive. The tests now pin each flow's lastSeen to a
distinct, increasing value after admitting it.

TestUDPTracker_Cleanup slept for timeout plus two ticker intervals and
raced the real ticker under load (macOS CI). It now drives the cleanup
routine with a test-owned tick channel, expires flows explicitly through
lastSeen, and also checks that a fresh flow survives the pass.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Conntrack tests now use distinct timestamps for cap eviction checks and a controlled tick for UDP cleanup checks. The cleanup test verifies that expired connections are removed while a fresh connection remains.

Changes: Conntrack test determinism

Layer / File(s) Summary
Distinct timestamps in cap tests
client/firewall/uspfilter/conntrack/cap_test.go
The TCP, UDP, and ICMP cap tests confirm that each flow is admitted, then assign it a distinct increasing lastSeen timestamp.
Controlled UDP cleanup test
client/firewall/uspfilter/conntrack/udp_test.go
The test sends a controlled tick after marking two connections expired. It cancels and joins the cleanup routine, then checks that only the fresh connection remains.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Suggested reviewers: lixmal

Merge Risk: Minimal · up to 631a5

This change only makes conntrack tests deterministic and does not alter runtime firewall behavior. No actionable merge risk remains.

Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
No Attribution Trailers Inconclusive Pull request inputs changed after this check was assessed; its verdict is no longer current. Re-run the check against the current pull request inputs.
Passed Passed checks: 4 passed

Check name Status Explanation
Title check Passed The title names the two changes in the PR: making the conntrack cap tests and the UDP cleanup test deterministic. It is specific and concise, and it matches the summary and objectives. It follows the …
Description check Passed The description covers the required sections: what changed and why, the issue or ticket section (stating no issue because the change is test-only), the stack section, the checklist, and the documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the two changes in the PR: making the conntrack cap tests and the UDP cleanup test deterministic. It is specific and concise, and it matches the summary and objectives. It follows the repository's [client] prefix style.

Full details: Description check

Explanation

The description covers the required sections: what changed and why, the issue or ticket section (stating no issue because the change is test-only), the stack section, the checklist, and the documentation choice with an explanation. The checklist items are marked. Two gaps remain. The docs PR URL line still holds the template placeholder, though the docs section says no docs are needed. The issue section gives a reason instead of a link, and the template requires a link for behavior changes. This change is test-only, so the template's own exception applies.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 3ae733c and 631a522.

Files selected for processing: 2

  • client/firewall/uspfilter/conntrack/cap_test.go
  • client/firewall/uspfilter/conntrack/udp_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@sonarqubecloud

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

View guided diff | Turn on auto-fix | Re-trigger cubic

@github-actions

Copy link
Copy Markdown

@mlsmaycon
mlsmaycon merged commit c4a6e4c into main Nov 14, 2026
58 checks passed
@mlsmaycon
mlsmaycon deleted the work/adoring-newton-yrav86 branch November 14, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants